ABC284 D - Happy New Year 2023
提出
code: python
t = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i == 0:
cnt = 0
while temp%i == 0:
cnt += 1
temp //= i
if temp != 1:
if arr == []:
return arr
for _ in range(t):
test = int(input())
# test = pow(p, 2)*q p,q: 素数
p = -1
q = -1
f = factorization(test)
for i in f:
print(p, q)
解答
code: python
t = int(input())
for test in tests:
for n in range(2, int(test**(1/3)) + 1):
# test の約数は、1, p, q, p*q, p^2, p^2*q
# 探索の範囲にあるのは p, q
if test % n == 0:
break
# n := p or q
if test % (n ** 2) == 0: # n := p
print(n, test // n**2)
else: # n := q
print(int((test//n) ** (1/2)), n)
メモ
提出
code: python
t = int(input())
print(tests)
# pow(10, 9) 以下の素数を列挙